<template>
  <div class="el-div">
    <div class="el-div el-s">
      <el-input
        v-model="input"
        placeholder="请输入任务名称"
        size="mini"
      ></el-input>
    </div>
    <div class="el-div">
      <el-button
        type="primary"
        icon="el-icon-search"
        size="mini"
        @click="search()"
      >搜索
      </el-button
      >
    </div>
    <div class="el-div">
      <el-button @click="cz()" size="mini">重置</el-button>
    </div>
    <div class="el-div">
      <el-button
        type="primary"
        @click="
          dialogFormVisible = true;
          addJobPage();
        "
        size="mini"
      >添加任务
      </el-button
      >
      <el-dialog :title="title" :visible.sync="dialogFormVisible" width="30%">
        <el-form>
          <el-form-item label="任务名称：" :label-width="formLabelWidth">
            <el-input
              v-model="name"
              autocomplete="off"
              placeholder="请输入任务名称"
              size="mini"
              style="width: 198px"
            ></el-input>
          </el-form-item>
          <el-form-item label="执行用例集：" :label-width="formLabelWidth">
            <el-select
              v-model="groupIds"
              multiple
              collapse-tags
              placeholder="请选择用例集"
              autocomplete="off"
              size="mini"
              style="width: 198px"
            >
              <el-option
                v-for="item in groupList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="执行环境：" :label-width="formLabelWidth">
            <el-select
              v-model="envId"
              collapse-tags
              placeholder="请选择环境变量"
              autocomplete="off"
              size="mini"
              style="width: 198px"
            >
              <el-option
                v-for="item in envList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="任务状态：" :label-width="formLabelWidth">
            <el-select
              v-model="statusModel"
              collapse-tags
              autocomplete="off"
              size="mini"
              style="width: 198px"
            >
              <el-option
                v-for="item in status"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="任务规则:" :label-width="formLabelWidth">
            <el-input v-model="cronExpression" autocomplete="off" placeholder="请输入正则表达式内容"
                      size="mini" style="width: 350px">
            </el-input>
          </el-form-item>
          <el-form-item label="邮件通知:" :label-width="formLabelWidth">
            <el-switch v-model="isSendEmail" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
            <el-input v-model="emailList" v-show="isSendEmail" autocomplete="off" placeholder="请输入需要通知邮件，以,隔开"
                      size="mini" style="width: 220px">
            </el-input>
          </el-form-item>
          <el-form-item label="钉钉通知:" :label-width="formLabelWidth">
            <el-switch v-model="isSendDingDing" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </el-form-item>
          <el-form-item label="任务描述：" :label-width="formLabelWidth">
            <el-input
              v-model="remark"
              autocomplete="off"
              placeholder="请输入用例描述"
              size="mini"
              type="textarea"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false" size="mini"
          >取 消
          </el-button
          >
          <el-button type="primary" @click="addJob()" size="mini">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <el-table :data="jobList.data.list" border size="mini">
      <el-table-column
        type="index"
        label="序号"
        width="80"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="jobName"
        label="任务名称"
        width="300"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="remark"
        label="任务描述"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        align="center"
        :formatter="getStatus"
      ></el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="300"
        align="center"
        :formatter="formatter"
      ></el-table-column>
      <el-table-column label="操作" align="center" width="260">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
          >编辑
          </el-button
          >
          <el-button type="primary" size="mini" @click="handleRun(scope.$index, scope.row)"
          >执行
          </el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
          >删除
          </el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      layout="total,sizes,prev,pager,next,jumper"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="jobList.data.pageSize"
      :current-page="jobList.data.pageNamber"
      :total="jobList.data.total"
      style="float: right; margin-top: 10px; margin-bottom: 10px"
      :small="true"
    >
    </el-pagination>
  </div>
</template>

<script>
  import index from './index';

  export default index;
</script>

<style scoped>
  @import "index.css";
</style>
